// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors, sized_box_for_whitespace, avoid_unnecessary_containers, avoid_print

import 'package:flutter/material.dart';
import 'package:mybaseplus/base/abstract/IFFR.dart';
import 'package:mybaseplus/base/abstract/IFFRefresh.dart';
import 'package:mybaseplus/base/abstract/IFFScaffold.dart';
import 'package:mybaseplus/base/tool/globalMethod/FFScreenValue.dart';
import 'package:mybaseplus/base/widget/layout/FFContainer.dart';
import 'package:mybaseplus/base/widget/layout/FFNavi2.dart';
import 'package:mybaseplus/base/widget/page/FFScaffold.dart';
import 'package:mybaseplus/base/tool/extension/FFListExt.dart';
import 'package:mybaseplus_example/const/ImgConst.dart';
import 'package:mybaseplus_example/pages/other/led/LEDWidget.dart';

class LEDPage extends FFScaffold {
  String? name;

  LEDPage({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  LEDPageState createState() => LEDPageState();
}

class LEDPageState extends FFScaffoldState with MFFScaffold {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  LEDPage get widget => super.widget as LEDPage;

  @override
  IFFRefresh? get iffRefresh => refresh;
  late LEDPageRefresh refresh = LEDPageRefresh(state: this);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNavi2.createNavi(
      context,
      title: "LED",
      titleCenter: true,
      actions: [
        FFNavi2Action(
          type: FFNavi2ActionType.img,
          value: ImgConst.imgred1,
          onClick: () {},
        ),
      ],
    );
  }

  @override
  Widget? ffBody(BuildContext context) {
    return Center(
      child: AspectRatio(
        aspectRatio: globalScreenHeight(context) / globalScreenWidth(context),
        child: FFContainer(
          width: globalScreenWidth(context),
          child: LEDWidget(
            isRepeat: true,
            param: [
              LEDWidgetParam(
                value: 'Hi you',
                speed: 0.5,
                textStyle: TextStyle(
                  fontSize: 120,
                  color: Colors.yellow,
                  height: 1.2,
                ),
              ),
              LEDWidgetParam(
                value: ImgConst.imgred1,
                speed: 0.5,
                textStyle: TextStyle(
                  fontSize: 120,
                  color: Colors.yellow,
                  height: 1.2,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

class LEDPageRefresh with MFFRefresh {
  LEDPageState state;

  LEDPageRefresh({required this.state});

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  //具体请求业务
  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    List? list;
    await Future.wait([
      //HomeApi.index_recentlyPlayed(),
    ]).then((value) {
      list = value;
    });

    IFFR? r = list?.safeValue(0);
    return r ?? R(rStatus: RStatus.result);
  }
}
